package com.songlanyun.modules.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.songlanyun.modules.goods.dao.GoodsGroupRelationDao;
import com.songlanyun.modules.goods.entity.GoodsGroupRelation;
import com.songlanyun.modules.goods.service.GoodsGroupRelationService;


@Service("goodsGroupRelationService")
public class GoodsGroupRelationServiceImpl extends ServiceImpl<GoodsGroupRelationDao, GoodsGroupRelation> implements GoodsGroupRelationService {

    private void clearByGoodsId(Long authId) {
        LambdaQueryWrapper<GoodsGroupRelation> wrapper =  new LambdaQueryWrapper<>();
        wrapper.eq(GoodsGroupRelation::getGoodsAuthShopId,authId);
        this.baseMapper.delete(wrapper);
    }

    @Override
    public void branchCreate(Long authId,List<GoodsGroupRelation> list) {
        if(list.size()>0)
        {
            clearByGoodsId(authId);
            list.forEach(g->{
                this.baseMapper.insert(g);
            });
        }
    }
}